package com.doordu.soa.service.data.service.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.doordu.soa.service.comm.utils.SpringContextHolder;
import com.doordu.soa.service.data.service.ParkingImageService;

/**
 * 图片同步线程
 * 
 * @ClassName: ImageSyncThread
 * @Description:
 * @author xiaoqun.yi yixq@doordu.com
 * @date 2017年9月26日 上午11:38:08
 * @version V1.0
 */
public class ImageSyncThread implements Runnable {
	private final Logger logger = LoggerFactory.getLogger(ImageSyncThread.class);
	private static ParkingImageService parkingImageService = null;

	@Override
	public void run() {
		logger.error("*******ServiceThreadStart--process--begin*******");
		while (true) {
			try {
				if(null==parkingImageService){
					parkingImageService = SpringContextHolder.getBean(ParkingImageService.class);
				}
				parkingImageService.syncLightcarImage();
			} catch (Exception e) {
				logger.error("", e);
			} finally {
				logger.error("*******ServiceThreadStart--process--end*******");
				sleepMinuts(5);
			}
		}
	}

	protected void sleepMinuts(long l) {
		sleep(1000 * 60 * l);
	}

	private void sleep(long l) {
		try {
			Thread.sleep(l);
		} catch (Exception e) {
			logger.error("", e);
		}
	}

	/**
	 * 检查Service Bean是否加载完毕
	 */
	public boolean isNullServiceBean() {
		if (parkingImageService == null) {
			return true;
		}
		return false;
	}
}
